package com.xww.stock.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: tangkeqiang
 * @Desription:
 * @Date: Created in 下午3:37 2020/04/16
 * @Modified By: tangkeqiang
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Value("${swagger.host}")
    private String swaggerHost;
//            "localhost:8880";

//    @Bean
//    public Docket createRestApi() {
//        List<Parameter> parameters = new ArrayList<>();
//        parameters.add(new ParameterBuilder()
//                .name("Authorization")
//                .description("认证token")
//                .modelRef(new ModelRef("String"))
//                .parameterType("header")
//                .required(false)
//                .build());
//        return new Docket(DocumentationType.SWAGGER_2)
//                //.host(swaggerHost)
//                .apiInfo(apiInfo())
//                .select()
//                .paths(Predicates.not(PathSelectors.regex("/error.*")))
//                .apis(RequestHandlerSelectors.any())
//                .paths(PathSelectors.any())
//                .build()
//                .apiInfo(apiInfo())
//                .globalOperationParameters(parameters);
//    }
//
//
//
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("[商城]")
                .termsOfServiceUrl("127.0.0.1:8880")
                .contact("xww")
                .description("微商城")
                .version("0.0.1")
                .build();
    }

    @Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xww.stock.controller"))
                .build()
                .apiInfo(apiInfo());
    }

//
}
